<?php
namespace Ygcl\Controller;
use Admin\Controller\AdminbaseController;
use Admin\Controller\PublicController;
class CacheadminController extends AdminbaseController {
	
	protected $m;
	protected $dService;
	protected $cService;
	protected $lService;
	
	function _initialize() {
		parent::_initialize();
		$this->dService = D('District','Service');
		$this->cService = D('Class','Service');
		$this->lService = D('Lesson','Service');
	}
	
	public function index(){
		$this->display();
	}
	
    //获取校区权限
    public function create_all_cahce(){
    	//更新校区缓存
    	$this->dService->_create_cache_district();
    	//更新课程缓存
    	$this->cService->_create_cache_class_classtype();
    	
    	$this->success('缓存更新成功');
    }
    
    public function update_student_lesson_num(){
    	set_time_limit(0);
    	$infos = M('LessonStudentRelation')->where(array('status'=>1))->select();
    	foreach ($infos as $in){
    		$lid = $in['lid'];
    		$xuenian_arr = explode(',',$in['xuenian']);
    		foreach ($xuenian_arr as $xn){
    			$xnid = R('Api/Termtime/get_xnid',array($xn));
    			$w = array('xnid'=>$xnid,'lid'=>$lid);
    			$m = M('YgclStudentNumber');
    			$info = $m->where($w)->find();
    			if($info){
    				$m->where($w)->setInc('number');
    			}else{
    				$w['number'] = 1;
    				$w['create_time'] = $w['update_time'] = date('Y-m-d h:i:s');
    				$m->add($w);
    			}
    		}
    	}
    	$this->ajaxReturn(array('status'=>1,'info'=>'更新完成'));
    }
    
    
    Public function update_student_lesson_old_status(){
    	set_time_limit(0);
    	$m = D('LessonStudentRelation');
    	$infos = $m->where(array('status'=>1,'orderid'=>array('neq','')))->relation(true)->select();
    	foreach ($infos as $in){
    		$data = array(
    			'id' => $in['id'],
    			'student_status' => $in['order']['studentstatus']
    		);
    		$m->save($data);
    	}
    	$this->ajaxReturn(array('status'=>1,'info'=>'更新完成'));
    }
}